//package com.xhwl.data.permission;
//
//import com.alibaba.fastjson.JSONObject;
//
//import com.xhwl.data.util.RedisUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//
//import javax.servlet.ServletContextEvent;
//import javax.servlet.ServletContextListener;
//import javax.servlet.annotation.WebListener;
//import java.util.Iterator;
//import java.util.Map;
//
//
///**
// * @Author: JCccc
// * @Description: 项目启动自动初始化所有接口对应的权限码关联关系数据
// * 注意，在application上需要加入注解 @ServletComponentScan 注解
// * @Date: 2020/11/24 9:07
// */
//
//@WebListener
//public class PermissionListener implements ServletContextListener {
//
//    private static final Logger log = LoggerFactory.getLogger(PermissionListener.class);
//    @Autowired
//    AnnotationUtil annotationUtil;
//    @Autowired
//    RedisUtils redisUtils;
//    @Value("${spring.application.name}")
//    private String APPLICATION_NAME;
//    @Value("${permission.controller.path}")
//    private String PERMISSION_CONTROLLER_PATH;
//    private static final String OAUTH = "OAUTH_";
//
//    @Override
//    public void contextInitialized(ServletContextEvent sce) {
//
//        log.info("项目={},PermissionListener正在执行权限参数初始化...", APPLICATION_NAME);
//        Map<String, Map<String, Object>> permissionsMap = null;
//
//        try {
//            String oauthSetKey = OAUTH + APPLICATION_NAME;
//            permissionsMap = annotationUtil.getAllAddTagAnnotationUrl(
//                    PERMISSION_CONTROLLER_PATH, Permission.class, APPLICATION_NAME);
//            Iterator<Map.Entry<String, Map<String, Object>>> iterator = permissionsMap.entrySet().iterator();
//            redisUtils.remove(oauthSetKey);
//            while (iterator.hasNext()) {
//                Map.Entry<String, Map<String, Object>> entry = iterator.next();
//                String key = entry.getKey();
//                Map<String, Object> value = entry.getValue();
//                JSONObject json = new JSONObject(value);
//                log.info("项目={},权限参数初始化 ,数据={}", APPLICATION_NAME, entry.toString());
//                redisUtils.hmSet(oauthSetKey, key, json);
//            }
//
//            log.info("项目={},PermissionListener权限参数初始化执行完毕。", APPLICATION_NAME);
//        } catch (Exception e) {
//            log.info("项目={},PermissionListener权限参数初始化执行异常。", APPLICATION_NAME);
//        }
//
//
//    }
//
//    @Override
//    public void contextDestroyed(ServletContextEvent sce) {
//        log.info("项目={} 关闭", APPLICATION_NAME);
//
//    }
//}
